import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'obs_controller.dart';

class ObsHomePage extends StatefulWidget {
  @override
  _ObsHomePageState createState() => _ObsHomePageState();
}

class _ObsHomePageState extends State<ObsHomePage> {
  @override
  Widget build(BuildContext context) {
    Get.put(ObsController());
    return Scaffold(
      appBar: AppBar(title: Text('响应式编程计数器')),
      body: Column(
        children: [buildColumn3()],
      ),
    );
  }

  buildColumn3() {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        // GetX<ObsController>(
        //     init: ObsController(),
        //     builder: (ObsController controller) {
        //       return Text("当前显示计数 ${controller.getCount}");
        //     }),
        Obx(() {
          return Text("当前显示计数 ${Get.find<ObsController>().getCount}");
        }),
        SizedBox(
          height: 30,
        ),
        ElevatedButton(
          onPressed: () {
            Get.find<ObsController>().add();
          },
          child: Text("添加"),
        ),
      ],
    );
  }
}
